<!DOCTYPE html>
<!--

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

-->
<html lang="en">
  <head>
    <title>Log</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <link rel="stylesheet" href="style/layout.css?0.11.0" type="text/css">

		<style type="text/css">
			p.help {
				float: left;
			}
			p.help input[type="number"] {
				width: 75px;
			}
			form[name="filter"] a {
				padding-right: 10px;
			}
			a#linkStopPolling {
				display: none;
			}
			table#config.listing tbody.content {
				white-space: pre;
				font-family: "DejaVu Sans Mono", Menlo, Courier, monospace;
			}
		</style>

    <script src="script/json2.js"></script>
    <script src="script/sha1.js"></script>
    <script src="script/jquery.js?1.4.2"></script>
    <script src="script/jquery.couch.js?0.11.0"></script>
    <script src="script/jquery.dialog.js?0.11.0"></script>
    <script src="script/futon.js?0.11.0"></script>
    <script>
			// Log-Polling-Object
			var LogPolling=new (function() {
				// Default values for polling
				this.defaults={
					"timeout": 1000,
					"bytes": 1000,
					"offset": 0
				};

				// Polling-Link-dom-ids
				this.runPollingId="linkRunPolling";
				this.startPollingId="linkStartPolling";
				this.stopPollingId="linkStopPolling";

				// Window-Timeout-Object
				this.windowTimeoutObject=null;

				// Function to return the value for polling to be timed out
				this.GetTimeout=function() {
					return ((timeout=$("form[name='filter'] input[name='timeout']").val())?timeout:this.defaults.timeout);
				}

				// Function to return the bytes for polling to retrieve
				this.GetBytes=function() {
					return ((bytes=$("form[name='filter'] input[name='bytes']").val())?bytes:this.defaults.bytes);
				}

				// Function to return the offset for polling to retrieve
				this.GetOffset=function() {
					return ((offset=$("form[name='filter'] input[name='offset']").val())?offset:this.defaults.offset);
				}

				// Function to run a single poll
				// Parameter: repeatTimeout, optional, used by .Start.function
				this.Run=function(repeatTimeout) {
					// Do polling
					$.ajax({
						"url": "/_log",
						"data": "bytes="+this.GetBytes()+"&offset="+this.GetOffset(),
						"error": function(jqXHR, textStatus, errorThrown) {
							// Main message
							var msg="Message: An error occured during retrieving _log.\n\n";

							// Add Text-Status
							msg+="Text status:\n"+textStatus+"\n\n";

							// Add errorThrown
							msg+="Error thrown:\n"+errorThrown+"\n\n";

							// Display error message
							alert(msg);
						},
						"success": function(data, textStatus, jqXHR) {
							// Put poll-data to content
							$("table#config.listing tbody.content").text(data);
						},
						"dataType": "html"
					});

					// Reapeat run, if it's timed out
					if (typeof repeatTimeout!="undefined") this.windowTimeoutObject=window.setTimeout(function() {
						LogPolling.Run(LogPolling.GetTimeout());
					}, repeatTimeout);
				}

				// Function to start _log-polling
				this.Start=function() {
					// Hide Run-Links
					$("#"+this.runPollingId).css("display", "none");
					$("#"+this.startPollingId).css("display", "none");
					// Show Stop-Link
					$("#"+this.stopPollingId).css("display", "inline");

					// Set up window-timeout-object to run polling
					this.Run(this.GetTimeout());
				}

				// Function to stop _log-polling
				this.Stop=function() {
					// Hide Run-Links
					$("#"+this.runPollingId).css("display", "inline");
					$("#"+this.startPollingId).css("display", "inline");
					// Show Stop-Link
					$("#"+this.stopPollingId).css("display", "none");

					// Kill Window-Timeout-Object
					if (this.windowTimeoutObject) {
						window.clearTimeout(this.windowTimeoutObject);
						this.windowTimeoutObject=null;
					}
				}
			});

			$(function() {
				LogPolling.Run();
			});
    </script>
  </head>
  <body><div id="wrap">
    <h1>
      <a href="index.html">Overview</a>
      <strong>Log</strong>
    </h1>
    <div id="content">
			<div>
				<p class="help">
					<b>Note:</b><br>
					For plain-text of <i>_log</i> click <a href="/_log" target="_blank">here</a>.
				</p>
				<form name="filter" onsubmit="return false;">
				<p class="help">
					<b>Filter:</b><br>
					Delay in miliseconds for polling: <input name="timeout" placeholder="1000" type="number">
					Bytes to retrieve: <input name="bytes" placeholder="1000" type="number">
					Bytes to offset: <input name="offset" placeholder="0" type="number"><br>
					<a href="javascript:LogPolling.Run();" id="linkRunPolling">Run polling once</a>
					<a href="javascript:LogPolling.Start();" id="linkStartPolling">Start continuous polling</a>
					<a href="javascript:LogPolling.Stop();" id="linkStopPolling">Stop continuous polling</a>
				</p>
				</form>
			</div>
      <table id="config" class="listing" cellspacing="0">
        <caption>Log</caption>
        <thead><tr>
          <th>Log-Entries</th>
        </tr></thead>
        <tbody class="content"></tbody>
      </table>
			<div id="logContent">
			</div>
    </div>
  </div></body>
</html>
